///<reference types="@i3yun/viewer" />
import { Container } from '../Container';
import { BaseGui } from "../Services/BaseGui";
import { DataService } from "../Services/DataService";
import { ViewerService } from "../Services/ViewerService";
import { SettingService } from "../Services/SettingService";
export class SettingGui extends BaseGui {
    title = `视图设置[${SettingGui.name}]`;
    private DataService = Container.defineProperty(DataService);
    private ViewerService = Container.defineProperty(ViewerService);
    private SettingService = Container.defineProperty(SettingService);
    getData() {
        return this.SettingService.getData();
    }
    async UpdateGui() {
        let data = this.getData().setting;
        let gui = this.gui;

        let fun = data as any;
        let funEvent = {
            _lightPresetOptions: () => {
                let names = {} as any;
                for (let i = 0; i < 19; i++)
                    names[i.toString()] = i;
                return names;
            },
            _Change: () => {
                this.updateViewer();
            }
        }

        let updateGUI = () => {
            Array.from(gui.__controllers).forEach(_ => {
                gui.remove(_);
            });
            this.guiService.buildGUIByObject(gui, fun, funEvent);
        }
        updateGUI();
        return this;
    }
    updateViewer() {
        return this.SettingService.updateViewer();
    }
    Init(): void {
        this.DataService.OnDataChanged.addEventListener(() => {
            this.Refresh();
        });
        this.SettingService.DataChanged.addEventListener(()=>{
            this.Refresh();
        })
        this.ViewerService.ViewerPromise.then((viewer) => {
            viewer.addEventListener(Sippreep.Viewing.MODEL_ROOT_LOADED_EVENT, () => {
                this.updateViewer();
            });
        });
    }
}